package ar.com.cooker.services.util;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;


public class PropertyManager {

	public static final String FILENAME = "cooker.properties";
	
	public static final String PATHMP3TEMP  = "path.mp3.temp";
	public static final String PATHMP3  = "path.mp3.def";
	public static final String WGET     = "wget.command";
	public static final String WRAP     = "mp3wrap.command";
		
	private Properties prop = null;
	private static PropertyManager instance = null;
	private FileInputStream fis = null;
		
	private PropertyManager(){
		
		try {
			prop = new Properties();
			fis  = new FileInputStream(PropertyManager.FILENAME);
			prop.load(fis);		
		} catch(IOException e) {
			e.printStackTrace();
		}
	}
	
	public void closeFile(){
		try {
			fis.close();
			prop = null;			
		} catch (IOException e) {
			System.out.println("Se produjo el siguiente error al "+
					"querer cerrar el archivo de properties: ");
			e.printStackTrace();
		}
	}
	
	public static PropertyManager getInstance(){
		if(instance==null || instance.prop == null) 
			instance = new PropertyManager();
		return instance;
	}
	
	public String getProperty(String clave){
		return prop.getProperty(clave);
	}
	
	public String getPathToMp3(){
		return prop.getProperty(PropertyManager.PATHMP3);
	}
	
	public String getPathToMp3Temp(){
		return prop.getProperty(PropertyManager.PATHMP3TEMP);
	}
	
	public String getWget(){
		return prop.getProperty(PropertyManager.WGET);
	}
	
	public String getWrap(){
		return prop.getProperty(PropertyManager.WRAP);
	}
}
